#ifdef ARCTIC
/**
 @file sys_at_qos.h

 @date 2018-03-06

 @version v1.0

 The file contains arctic QoS funcation
*/

#ifndef _SYS_AT_QOS_H
#define _SYS_AT_QOS_H
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
extern sys_queue_master_t* p_usw_queue_master[CTC_MAX_LOCAL_CHIP_NUM_PP];

#define SYS_MAX_DROP_FACTOR 10

#define SYS_AT_NON_UC_BUFFER_SIZE_DEFAULT 32768
#define SYS_AT_PORT_MIN_GUARANTEE 80
/* 0x3FF means disable guarantee*/
#define SYS_AT_MAX_GUARANTEE 0x3FF
#define SYS_AT_NETWORK_GROUP_NUM 52
#define SYS_AT_DMA_GROUP_NUM_UC 4
#define SYS_AT_DMA_GROUP_NUM_MC 16
#define SYS_SUB_CHAN_MASK 0x1F
#define SYS_DMA_SUB_CHAN  24
#define SYS_LOOP_SUB_CHAN  25
#define SYS_CHAN_TO_DP_ID(subchanId) (((subchanId) >> 5) & 0x1)
#define SYS_CHAN_TO_PP_ID(subchanId) ((((subchanId) >> 6) & 0x3)+(((subchanId) >> 8) & 0x1)*SYS_CORE_PP_NUM(lchip))
#define SYS_AT_LIMIT_MAX_THRD_UC 0x7FFE
#define SYS_AT_LIMIT_MAX_THRD_MC 0x1FFE
#define SYS_AT_LIMIT_MAX_THRD_MC_IRM 0x7FFE

#define SYS_QOS_LCHIP_CONVERT(lchip, pp_id) \
    { \
        CTC_MAX_VALUE_CHECK(pp_id, (SYS_PP_NUM(lchip)-1));\
        lchip = SYS_PP_BASE(lchip) + (pp_id);\
    }

#define SYS_AT_GROUP_ID(group_id, p_queue_node) \
    { \
        if (SYS_QUEUE_TYPE_NORMAL == (p_queue_node)->type || SYS_QUEUE_TYPE_EUNIT == (p_queue_node)->type) \
        {\
            group_id = (p_queue_node)->sub_chan + (p_queue_node)->dp_id * MCHIP_CAP(SYS_CAP_PER_DP_CHANNEL_NUM);\
        }\
        else if (SYS_QUEUE_TYPE_EXCP == (p_queue_node)->type || SYS_QUEUE_TYPE_EXCP_UC == (p_queue_node)->type)/*dma Q*/ \
        {\
            group_id = MCHIP_CAP(SYS_CAP_QOS_BASE_QUEUE_GRP_NUM) + (p_queue_node)->offset / MCHIP_CAP(SYS_CAP_REASON_GRP_QUEUE_NUM);\
        }\
    }

#define SYS_AT_COS_SUB_NODE_OFST(p_que_node, class_prio) \
    ((((p_que_node)->node[0].type != SYS_QUE_OFST_NONE) && ((p_que_node)->node[1].type != SYS_QUE_OFST_NONE)) ? class_prio : ((p_que_node)->node[1].type != SYS_QUE_OFST_NONE ? 1 : 0))

#define SYS_AT_QOS_ENCOD_QBASE(dp_chan, pp_id, dp_id) (((dp_chan) + ((pp_id) * 2 + ((dp_id) & 0x1)) * MCHIP_CAP(SYS_CAP_PER_DP_CHANNEL_NUM)) * MCHIP_CAP(SYS_CAP_QOS_QUEUE_NUM_PER_CHAN))
#define SYS_AT_QOS_ENCOD_CORE_CHAN(dp_chan, pp_id, dp_id) ((dp_chan) + ((pp_id % SYS_CORE_PP_NUM(lchip)) * 2 + ((dp_id) & 0x1)) * MCHIP_CAP(SYS_CAP_PER_DP_CHANNEL_NUM))
#define SYS_AT_QOS_ENCOD_PP_CHAN(dp_chan, dp_id) ((dp_chan) + ((dp_id) & 0x1) * MCHIP_CAP(SYS_CAP_PER_DP_CHANNEL_NUM))
#define SYS_AT_QOS_ENCOD_DP_QUE_UC(dp_chan, uc_offset) ((dp_chan) * MCHIP_CAP(SYS_CAP_QOS_QUEUE_NUM_PER_CHAN) + (uc_offset))
#define SYS_AT_QOS_ENCOD_CORE_QUE_MC(dp_chan, pp_id, dp_id, mc_offset) (SYS_AT_QOS_ENCOD_CORE_CHAN(dp_chan, pp_id, dp_id) * SYS_AT_MC_QUEUE_NUM + (mc_offset))

#define SYS_DP_BY_SUB_CHAN(sub_chan) (((sub_chan) >> 5) & 0x1)
#define SYS_PP_BY_SUB_CHAN(sub_chan) (((sub_chan) >> 6) & 0x7)
#define SYS_DP_CHAN_BY_SUB_CHAN(sub_chan) ((sub_chan) & 0x1F)
#define SYS_PP_CHAN_BY_SUB_CHAN(sub_chan) (SYS_DP_CHAN_BY_SUB_CHAN(sub_chan) + SYS_DP_BY_SUB_CHAN(sub_chan)*MCHIP_CAP(SYS_CAP_PER_DP_CHANNEL_NUM))
#define SYS_AT_QOS_ENCOD_SUB_CHAN(pp_id, dp_id, dp_chan) ((pp_id&0x7) << 6 | (dp_id&0x1) << 5 | (dp_chan & 0x1F))

extern int32
sys_at_queue_get_queue_id(uint8 lchip, ctc_qos_queue_id_t* p_queue, uint16* queue_id);
extern int32
sys_at_get_sub_channel_by_channel(uint8 lchip, uint16 chan, uint16 *sub_chan);
extern int32
sys_at_get_channel_by_port(uint8 lchip, uint32 gport, uint16 *channel);
extern int32
sys_at_add_port_to_channel(uint8 lchip, uint32 lport, uint16 channel, uint8 is_pp);
extern int32
sys_at_remove_port_from_channel(uint8 lchip, uint32 lport, uint16 channel);
extern int32
sys_at_queue_set_port_drop_en(uint8 lchip, uint32 gport, bool enable, void* p_drop_param);
extern int32
sys_at_set_dma_channel_drop_en(uint8 lchip, bool enable);
extern int32
sys_at_queue_get_port_depth(uint8 lchip, uint32 gport, uint32* p_depth);
extern int32
sys_at_queue_get_channel_by_queue_id(uint8 lchip, uint16 queue_id, uint16 *channel);
extern int32
sys_at_get_channel_by_sub_channel(uint8 lchip, uint8 dp_id, uint8 sub_chan, uint16 *chan);
extern int32
sys_at_qos_set_shape(uint8 lchip, ctc_qos_shape_t* p_shape);
extern int32
sys_at_qos_get_shape(uint8 lchip, ctc_qos_shape_t* p_shape);
extern int32
sys_at_shape_get_que_shape_profile(uint8 lchip, uint16 queue_id, uint16 queue_offset, void* p_shape);
extern int32
sys_at_shape_get_port_shape_profile(uint8 lchip, uint16 channel, uint32* rate, uint32* thrd,
                                                              uint8* pps_en, uint8* p_shp_en);
extern int32
sys_at_qos_set_sched(uint8 lchip, ctc_qos_sched_t* p_sched);
extern int32
sys_at_qos_get_sched(uint8 lchip, ctc_qos_sched_t* p_sched);
extern int32
sys_at_sch_get_queue_sched(uint8 lchip, uint16 queue_id, uint8 queue_offset, uint8* exceed_class, uint16* exceed_weight);
extern int32
sys_at_qos_set_glb_wrr_enable(uint8 lchip, uint8 enable);
extern int32
sys_at_sch_set_wrr_en(uint8 lchip, sys_port_info_t* p_port_info, uint32 enable);
extern int32
sys_at_sch_get_wrr_en(uint8 lchip, sys_port_info_t* p_port_info, uint32* enable);
extern int32
sys_at_sch_set_net_chan_credit(uint8 lchip, sys_port_info_t* p_port_info, uint8 is_pps);
extern int32
sys_at_sch_set_dma_chan_credit(uint8 lchip, uint8 is_pps);
extern int32
sys_at_sch_set_ecpu_chan_credit(uint8 lchip, uint8 is_pps);
extern int32
sys_at_qos_queue_set(uint8 lchip, ctc_qos_queue_cfg_t* p_que_cfg, sys_cpu_reason_dest_info_t* p_dest_info);
extern int32
sys_at_qos_queue_get(uint8 lchip, ctc_qos_queue_cfg_t* p_que_cfg);
extern int32
sys_at_queue_set_drop(uint8 lchip, ctc_qos_drop_t* p_drop);
extern int32
sys_at_queue_get_drop(uint8 lchip, ctc_qos_drop_t* p_drop);
extern int32
sys_at_resrc_get_que_drop(uint8 lchip, void* p_sys_queue_node, void* p_sys_drop, uint8 wred_mode,  uint8* wtd_en, uint8* wred_en);
extern int32
sys_at_queue_set_resrc(uint8 lchip, ctc_qos_resrc_t* p_resrc);
extern int32
sys_at_queue_get_resrc(uint8 lchip, ctc_qos_resrc_t* p_resrc);
extern int32
sys_at_qos_set_fc_default_profile(uint8 lchip, uint32 gport);
extern int32
sys_at_qos_set_glb_port_shp_base_pkt_en(uint8 lchip, uint8 enable);
extern int32
sys_at_qos_set_glb_reason_shp_base_pkt_en(uint8 lchip, uint8 enable);
extern int32
sys_at_qos_resrc_mgr_en(uint8 lchip, uint8 enable);
extern int32
sys_at_queue_query_pool_stats(uint8 lchip, ctc_qos_resrc_pool_stats_t* p_stats);
extern int32
sys_at_queue_stats_query(uint8 lchip, ctc_qos_queue_stats_t* p_stats_param);
extern int32
sys_at_queue_stats_clear(uint8 lchip, ctc_qos_queue_stats_t* p_stats_param);
extern int32
sys_at_stats_query(uint8 lchip, ctc_qos_stats_type_t type, void* p_stats_param);
extern int32
sys_at_stats_clear(uint8 lchip, ctc_qos_stats_type_t type, void* p_stats_param);
int32
sys_at_queue_set_egs_resrc_guarantee(uint8 lchip, uint8 enable);
extern int32
sys_at_queue_enq_init(uint8 lchip, void *p_glb_parm);
extern int32
sys_at_queue_sch_init(uint8 lchip);
extern int32
sys_at_queue_shape_init(uint8 lchip);
extern int32
sys_at_queue_drop_init(uint8 lchip, void *p_glb_parm);
extern int32
sys_at_queue_drop_deinit(uint8 lchip);
extern int32
sys_at_queue_shape_deinit(uint8 lchip);
extern int32
sys_at_queue_sch_deinit(uint8 lchip);
extern int32
sys_at_queue_enq_deinit(uint8 lchip);

extern int32
sys_at_qos_queue_dump(uint8 lchip, uint16 start, uint16 end, uint8 detail);
extern int32
sys_at_qos_port_dump(uint8 lchip, uint32 start, uint32 end, uint8 detail);
extern int32
sys_at_qos_queue_dump_status(uint8 lchip);
extern int32
sys_at_qos_drop_dump_status(uint8 lchip);
extern int32
sys_at_qos_set_fcdl_action(uint8 lchip, uint32 action);
extern int32
sys_usw_qos_get_fcdl_action(uint8 lchip, uint32* action);
extern int32
sys_at_qos_set_fcdl_interval(uint8 lchip, uint32 time);
extern int32
sys_at_qos_get_fcdl_interval(uint8 lchip, uint32* time);
extern int32
sys_at_qos_set_round_trip_mode(uint8 lchip, uint32 mode);
extern int32
sys_at_qos_get_round_trip_mode(uint8 lchip, uint32* mode);
extern int32
sys_at_queue_traverse_queue_node(uint8 lchip, uint16 lport,
                                SYS_QOS_TRAVERSE_FUNC fn,
                                void* user_data);
extern int32
sys_at_queue_get_span_on_drop_mcq(uint8 lchip, sys_port_info_t* port_info, uint8* mcq);

#ifdef __cplusplus
}
#endif

#endif
#endif

